home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / tpapi.exe / EXAMPLES / SEMAPHOR.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-14  |  3KB  |  67 lines

  1. {***************************************************************************}
  2. {** Program : SEMAPHOR                                                    **}
  3. {***************************************************************************}
  4. {** Version : 1.0             ** Started :           ** Ended :           **}
  5. {***************************************************************************}
  6. {******************************** Description ******************************}
  7. {***************************************************************************}
  8. {** Program to demonstrate using semaphores for limiting how many users   **}
  9. {** can run this program.  This program can only have one copy of itself  **}
  10. {** running on a particular server.                                       **}
  11. {**                                                                       **}
  12. {**                                                                       **}
  13. {**                                                                       **}
  14. {**                                                                       **}
  15. {**                                                                       **}
  16. {***************************************************************************}
  17. {******************************** Information ******************************}
  18. {***************************************************************************}
  19. {**                                                                       **}
  20. {**                                                                       **}
  21. {**                                                                       **}
  22. {**                                                                       **}
  23. {**                                                                       **}
  24. {**                                                                       **}
  25. {***************************************************************************}
  26.  
  27. {$X+}
  28.  
  29. program SEMAPHOR;
  30.  
  31. uses
  32.  
  33.   nwvar,
  34.   nwsynch
  35.   ;
  36.  
  37. const
  38.  
  39.   InstancesAllowedToRun = 1;
  40.  
  41. var
  42.  
  43.   SS      : SynchronisationOBJ;
  44.   SHandle : longint;
  45.   OCount  : byte;
  46.  
  47. begin
  48.  
  49.   SS.Init (true);
  50.   SS.OpenSemaphore ('SEMAPHOR', 0, SHandle, OCount);
  51.   if OCount > InstancesAllowedToRun then
  52.     writeln ('This program is already at the user limit.')
  53.   else
  54.     begin
  55.  
  56.       writeln ('This program is only running on this pc');
  57.       writeln ('Go and attempt to run this program on another pc on');
  58.       writeln ('the same file server!');
  59.       writeln ('Please press enter to end.');
  60.       readln;
  61.  
  62.     end;
  63.  
  64.   SS.Done;
  65.  
  66. end.
  67.